package com.ljh.gmall.manage.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ljh.gmall.bean.*;
import com.ljh.gmall.service.SpuService;
import com.ljh.gmall.util.PmsUploadUtil;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author LJH
 * @date 2019/10/5 10:11
 */

@RestController
@CrossOrigin
public class SpuController {

    @Reference
    SpuService spuService;

    @GetMapping("spuList")
    public List<PmsProductInfo> spuList(@RequestParam("catalog3Id") String catalog3Id) {
        List<PmsProductInfo> pmsProductInfos = spuService.getSpuList(catalog3Id);
        return pmsProductInfos;
    }

    @PostMapping("baseSaleAttrList")
    public List<PmsBaseSaleAttr> baseSaleAttrList(){
        List<PmsBaseSaleAttr> pmsBaseSaleAttrs=spuService.getBaseSaleAttrList();
        return pmsBaseSaleAttrs;
    }

    @PostMapping("saveSpuInfo")
    public String saveSpuInfo(@RequestBody PmsProductInfo pmsProductInfo){

        String str=spuService.saveSpuInfo(pmsProductInfo);
        return str;
    }

    @PostMapping("fileUpload")
    public String fileUpload(@RequestParam("file")MultipartFile multipartFile){

        String url=PmsUploadUtil.uploadImage(multipartFile);
        return url;
    }


    @GetMapping("spuSaleAttrList")
    public List<PmsProductSaleAttr> spuSaleAttrList(@RequestParam("spuId")String spuId){
        List<PmsProductSaleAttr> spuSaleAttrList= spuService.spuSaleAttrList(spuId);
        return spuSaleAttrList;
    }


    @GetMapping("spuImageList")
    public List<PmsProductImage> spuImageList(@RequestParam("spuId")String spuId){
        List<PmsProductImage> pmsProductImages = spuService.spuImageList(spuId);
        return pmsProductImages;
    }

}
